<?php
namespace AdminApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class RegistrationApiController extends AbstractRestfulController
{
    public function getList()
    {			
		header('Access-Control-Allow-Origin: *');
		$request = $this->getRequest();
		$headers = $request->getHeaders();
		$data=array();		
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$userData = $userTable->getUserData($user_id)->toArray();
		if(count($userData)!=0){
			return new JsonModel(array(
				'data' => json_encode($data),
			));
		}else{
			return new JsonModel(array(
				'output' => 'no data',
			));
		}
    }
    public function get($user_id)
    {		
		header('Access-Control-Allow-Origin: *');
		$data=array();		
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$userData = $userTable->getUserData($user_id);
		if(count($userData)!=0){
			foreach($userData as $user){
				$data[]=$user;
			}
			return new JsonModel(array(
				'data' 	=> json_encode($data),
				'value'	=> 1,
			));
		}else{
			return new JsonModel(array(
				'output' => 'no data',
				'value'	=> 0,
			));
		}
    }
    public function create($data)
    {
		header('Access-Control-Allow-Origin: *');
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$shopData = $userTable->getShopsByFilter($data)->toArray();
		if(count($shopData)!=0){
			return new JsonModel(array(
				'result' => json_encode($shopData),
				'output' =>'success',
				'value' =>1,
			));
		}else{
			return new JsonModel(array(
				'output' => 'no data',
				'value' =>0,
			));
		}
    }
    public function update($data,$uid)
    {
		header('Access-Control-Allow-Origin: *');	
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$notificationTable=$this->getServiceLocator()->get('Models\Model\NotificationsFactory');
		$result = $userTable->changeUserStatus($data,$uid);
		
		/*
		$getDetailes = $userTable->getDetailes($data,$uid)->toArray();
		$complint_name=$uid['complint_name'];
		global activeBlockMessage;
		global activeBlockSubject;
		$activeBlockMessage = str_replace("<STATUS>","$complint_name", $activeBlockMessage);
		$activeBlockSubject = str_replace("<SUBSTATUS>","$complint_name", $activeBlockMessage);
		$to=$getDetailes[0]['email'];	
			if(sendMail($to,$activeBlockSubject,$activeBlockMessage)){
			}
		*/
		if($uid['user_type_id']==3){
			$sendActiveNotification=$notificationTable->sendshopActiveNotification($uid,'1','0',$data,'0','3','0');
		}else{
			$sendActiveNotification=$notificationTable->sendshopActiveNotification($uid,'1','0','0','0','3',$data);
		}
		
		if($result!=0){
			return new JsonModel(array(
				'output' => 'success',
			));
		}else{
			return new JsonModel(array(
				'output' => 'not success',
			));
		}
    }
    public function delete($id)
    {
       
    }
}